/*
 * @lc app=leetcode.cn id=383 lang=javascript
 *
 * [383] 赎金信
 */

// @lc code=start
/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function(ransomNote, magazine) {
    let store={};
    [...magazine].forEach((item)=>{
        if(store[item]){
            store[item]++
        }else{
            store[item]=1
        }
    });
    return [...ransomNote].every((item)=>{
        return store[item]&&--store[item]>=0
    })
};//hash计数
// @lc code=end

var canConstruct = function (ransomNote, magazine) {
    for (let i = 0; i < ransomNote.length; i++) {
        if (magazine.indexOf(ransomNote[i]) === -1) {
            return false;
        }
        magazine = magazine.replace(ransomNote[i], "");
    }
    return true;
};//已经替代过就用replace标记

